import { Application } from "../App";
import vtkActor from "@kitware/vtk.js/Rendering/Core/Actor";
import { ArrayPlus } from "../Core/ArrayPlus";

export class NormalSystem {
  parent: Application;
  normalActors: ArrayPlus<vtkActor> = new ArrayPlus<vtkActor>([]);

  constructor(parent: Application) {
    this.parent = parent;
  }

  add(ac: vtkActor) {
    this.normalActors.push(ac);
  }

  remove(ac: vtkActor) {
    this.normalActors.remove(ac);
  }

  // 更新
  update() {
    const list = this.parent.actorList;
    list.foreach((actor) => {
      if (actor.triggerNormalUpdate === 0) return;
      if (actor.isShowNormals) {
        const b = actor.getNormalActor();
        if (b) {
          console.log(b);
          this.parent.renderer.addActor(b);
        }
      } else {
        const b = actor.getNormalActor();
        if (b) {
          this.parent.renderer.removeActor(b);
        }
      }
      actor.triggerNormalUpdate = 0;
    });
  }
}
